package com.yc.testPro;

public class TestJavaBase {
	
	public void m1() {
//		Short myshort = 99S;
//		char c = 17c;
		String aa = "aaa";
		int b = aa.length();
		int t = "abc".length();
	}
	
	public void m2() {
		int a = 2;
		assert(a < 1);
	}
	
	public void m3() {
		int i = 32;
//		System.out.println(i << 1);
//		System.out.println(i << 2);
//		System.out.println(i << 3);
//		System.out.println(i << 4);
//		
//		System.out.println(i << 5);
//		System.out.println(i << 6);
//		System.out.println(i << 7);
//		System.out.println(i << 8);
//		
//		System.out.println(i << 9);
		//-----------------------------
		System.out.println("(i >> 1)=" + (i >> 1));
		System.out.println("(i >> 2)=" + (i >> 2));
		System.out.println("(i >> 3)=" + (i >> 3));
		System.out.println("(i >> 4)=" + (i >> 4));

		System.out.println("(i >> 5)=" + (i >> 5));
		System.out.println("(i >> 6)=" + (i >> 6));
		System.out.println("(i >> 7)=" + (i >> 7));
		System.out.println("(i >> 8)=" + (i >> 8));

		System.out.println("(i >> 9)=" + (i >> 9));
		System.out.println("(i >> 10)=" + (i >> 10));
		System.out.println("(i >> 11)=" + (i >> 11));
		System.out.println("(i >> 12)=" + (i >> 12));
		System.out.println("(i >> 13)=" + (i >> 13));
		System.out.println("(i >> 14)=" + (i >> 14));
		System.out.println("(i >> 15)=" + (i >> 15));
		System.out.println("(i >> 16)=" + (i >> 16));
		System.out.println("(i >> 17)=" + (i >> 17));
		System.out.println("(i >> 18)=" + (i >> 18));
		
	}
	
	public void testString() {
		String s1 = "abc";
		String s4 = new String("abc");
		System.out.println(s1==s4);
	}
	
	public void m4(String str, int i) {
		byte[] b = new byte[1024];
		int num = 0;
		
		b = str.getBytes();
		if (b[i-1] > 0) {
			System.out.println(new String(b, 0, i));
		} else {
			for (int j = 0; j < i; j++) {
				if (b[j] < 0) {
					num++;
					num = num%2;
					
				} else {
					num = 0;
				}
			}
			
			if (num == 0) {
				System.out.println(new String(b, 0, i));
			} else {
				System.out.println(new String(b, 0, i-1));
			}
		}
	}
	
	public String toHexString(byte[] byteArray) {
		if (byteArray == null || byteArray.length < 1)
			throw new IllegalArgumentException("this byteArray must not be null or empty");

		final StringBuilder hexString = new StringBuilder();
		for (int i = 0; i < byteArray.length; i++) {
			if ((byteArray[i] & 0xff) < 0x10)// 0~F前面不零
				hexString.append("0");
			hexString.append(Integer.toHexString(0xFF & byteArray[i]));
		}
		return hexString.toString().toLowerCase();
	}
	
	public void m5(char c) {
		System.out.println((int)c);
	}
	
	public void m6() {
		/**
		 *  -28
			-72
			-83
			-27
			-101
			-67
			65
			-26
			-120
			-111
		 */
		String str = "中国A我";
		byte[] b = str.getBytes();
		
		for (byte c : b) {
			System.out.println(c);
		}
	}
	
	public void m7() {
		/**
		 *  -28
			-72
			-83
			-27
			-101
			-67
			65
		 */
		String str = "中国A我";
		byte[] b = str.getBytes();
		
		System.out.println(b[0]);
		System.out.println(b[1]);
		System.out.println(b[2]);
		System.out.println(b[3]);
		System.out.println(b[4]);
		System.out.println(b[5]);
		System.out.println(b[6]);
	}

	public static void main(String[] args) {
		
		String str = "中国A我";
		byte[] b = str.getBytes();
		
		TestJavaBase tjb = new TestJavaBase();
//		System.out.println(tjb.toHexString(b));
//		tjb.m5('中');//20013
//		tjb.m5('国');//22269
//		tjb.m5('A');//65
//		tjb.m5('我');//25105
		
//		tjb.testString();
//		tjb.m6();
		tjb.m7();
//		tjb.m4(str, 4);
	}
}
